$(function() {
    window.heroModel = Backbone.Model.extend({
        defaults : function() {
            return {};
        },
        initialize : function() {

        },
        parse : function(data) {//fetch,save 触发
            var heroId = data['HID'];
            var recommend = [];
            recommend = $.grep(appGlobal.recommend, function(val, key) {
                val["Desc"] = val["Desc"] || val["Title"];
                //设置默认值
                if(val["HID"] == heroId) {
                    return true;
                }
            }, false);
            //获取属于当前英雄的推荐方案
            var userConfig = HeroesApp.getConfig("web_hero" + heroId, false);
            var talents = window.appGlobal._parseHeroTalents(data, recommend, userConfig);
            data["id"] = heroId;
            data["Title"] = data["Title"] || data["Name"];

            //设置默认值
            data["talents"] = talents;
            data["recommend"] = recommend;

            return data;
        }
    });

    window.heroList = Backbone.Collection.extend({
        model : heroModel,
        url : heroListJsonUrl,
        parse : function(data) {
            //初始化全局变量
            appGlobal.weekfree = data["data"]["周免"];
            appGlobal.talent = data["data"]["天赋"];
            appGlobal.skill = data["data"]["技能"];
            appGlobal.recommend = data["data"]["推荐天赋"];

            data = data["data"]["英雄"];
            //console.log(data);
            return data;
        }
    });

    window.heroView = Backbone.View.extend({
        tagName : "div",

        template : _.template($('#hero_view_template').html()),

        events : {
            "click" : "selectHero",
            "mouseover" : "mouseoverHero",
            "mouseout" : "mouseoutHero"
        },

        initialize : function() {
            this.listenTo(this.model, 'change', this.render);
            this.listenTo(this.model, 'destroy', this.remove);

            this.$el.addClass("hero").addClass("clearfix");
            this.$el.attr("data-heroId", this.model.get("HID"));
            this.$el.addClass(this.model.get("belongsTo"));
        },

        render : function() {
            this.$el.html(this.template(this.model.toJSON()));
            return this;
        },

        selectHero : function(e) {
            if($(e.currentTarget).hasClass(".active")) {
                return false;
            } else {
                window.myPageView.$("#heroList .hero").removeClass("active");
                window.myPageView.$("#heroList .hero .face .activeImg").hide();

                $(e.currentTarget).addClass("active");
                $(e.currentTarget).find(".activeImg").show();

                this.setMapList();

                //设置名字
                $("#mapList .name").text("- " + this.model.get("Name") + " -");
                //appGlobal.onHeroChange($(e.currentTarget).attr("data-heroid"));
            }
        },

        mouseoverHero : function(e) {
            $(e.currentTarget).find(".hoverImg").show();
        },

        mouseoutHero : function(e) {
            $(e.currentTarget).find(".hoverImg").hide();
        },

        setMapList : function() {
            //先清除，再添加
            this.clearPlan();

            $.each(this.model.get("recommend"), function(index, plan) {
                var element = $("#mapList .mapWrapper[data-mid=" + plan['Map'] + "]");
                element.find(".selectWrapper select").append("<option value=" + plan['TRID'] + ">" + plan['Title'] + "</option>")
            });

            //设置默认值
            $.each(this.model.get("talents"), function(index, plan) {
                var element = $("#mapList .mapWrapper[data-mid=" + plan['Map'] + "]");
                element.find(".selectWrapper select").val(plan["TRID"]);
            });
        },

        clearPlan : function() {
            $("#mapList .selectWrapper option").remove();
        }
    });

    window.horseModel = Backbone.Model.extend({
        defaults : function() {
            return {};
        },
        initialize : function() {

        },
        parse : function(data) {//fetch,save 触发
            //console.log(data);
            for(var i in data["color"]) {
                appGlobal.color.push(data["color"][i]);
                //创建appGlobal.color
            }
            return data;
        }
    });

    window.horseList = Backbone.Collection.extend({
        model : horseModel,

        url : horseListJsonUrl,
        parse : function(data) {
            data = data["坐骑"];

            appGlobal.color = [0];
            //初始化全局变量,清空appGlobal.color
            //console.log(data);
            return data;
        }
    });

    window.horseView = Backbone.View.extend({
        tagName : "li",

        template : _.template($('#horse_view_template').html()),

        events : {
            "click" : "clickHorse",
            "mouseover" : "mouseoverHorse",
            "mouseout" : "mouseoutHorse"
        },

        initialize : function() {
            this.listenTo(this.model, 'change', this.render);
            this.$el.attr("data-hid", this.model.get("hid"));
        },

        render : function() {
            this.$el.html(this.template(this.model.toJSON()));
            return this;
        },

        clickHorse : function(e, init) {
            if($(e.currentTarget).hasClass("active")) {
                return false;
            } else {
                $("#selectHorse ul li").removeClass("active");
                $("#selectHorse ul li .activeImg").fadeOut();
                $(e.currentTarget).addClass("active");
                $(e.currentTarget).find(".activeImg").fadeIn();

                var hid = $(e.currentTarget).attr("data-hid");
                HeroesApp.setConfig("web_horseIndex", hid);
                //设置配置文件

                this.setPreview(init);
            }
        },
        mouseoverHorse : function(e) {
            $(e.currentTarget).find(".hoverImg").show();
            var top = $(e.currentTarget).find(".thumbnail").offset().top + $(e.currentTarget).find(".thumbnail").height() + 5;
            var left = $(e.currentTarget).offset().left + 5;
            $("#tips_horse").text(this.model.get("desc")).css({
                left : left,
                top : top
            }).addClass("in");
        },
        mouseoutHorse : function(e) {
            $(e.currentTarget).find(".hoverImg").hide();

            $("#tips_horse").removeClass("in");
        },

        setPreview : function(init) {
            //设置颜色
            $("#horse_preview .color.active").removeClass("active")
            var colors = this.model.get("color");
            for(var i = 0; i < colors.length; i++) {
                var url = "data/Horse/" + colors[i] + ".png";

                $("#horse_preview .color img:eq(" + i + ")").attr("src", url).parent().attr("data-color", colors[i]);
            }
            //设置第一个颜色为默认值
            if(!init) {//init为函数参数,表示是否是初始化时候调用
                $("#horse_preview .color:eq(0)").trigger("click");
            }

        }
    });

    window.shopView = Backbone.View.extend({
        tagName : "div",

        template : _.template($('#shop_template').html()),

        events : {
            "click #horse_preview .color" : "clickColor",
        },

        initialize : function() {
            //console.log("shop init:" + appGlobal.enable.shop)
            if(appGlobal.enable.shop == "false") {
                this.$el.html("<img id='comming_soon' src=img/comming_soon.png />");
                $("#main").html(this.el);
                return false;
            }

            this.listenTo(window.myHorseList, 'add', this.addOne);
            this.listenTo(window.myHorseList, 'reset', this.addAll);

            this.render();

            var handle = this;

            window.myHorseList.fetch({
                success : function() {
                    handle.setHorse(HeroesApp.getConfig("web_horseIndex"), true);

                    setTimeout(function() {
                        if(!HeroesApp.getConfig("web_IsNotFirstTime_shop", false)) {
                            appGlobal._show_first_shop_tips_modal();
                        }
                    }, 200)
                }
            });

        },

        render : function() {
            this.$el.html(this.template());
            $("#main").html(this.el);
            $("#page").fadeIn("slow");

            return this;
        },

        addOne : function(horse) {
            var view = new horseView({
                model : horse
            });
            this.$("#selectHorse ul").append(view.render().el);
        },

        addAll : function() {
            window.myHeroList.each(this.addOne, this);
        },

        clickColor : function(e) {
            if($(e.currentTarget).hasClass("active")) {
                return;
            }
            var color = $(e.currentTarget).attr("data-color");
            var colorId = appGlobal.color.indexOf(color).toString();

            var preview_url = "data/Horse/" + color + "_preview.png";

            $("#big_preview").fadeOut(300);

            setTimeout(function() {
                $("#big_preview").attr("src", preview_url);
            }, 300);
            $("#big_preview").fadeIn(300);

            this.$("#horse_preview .color.active").removeClass("active");
            $(e.currentTarget).addClass("active");
            //console.log(color);
            HeroesApp.setConfig("web_color", color);

            //判断用户设置是否可用
            if(HeroesApp.getConfig("web_enableHorse", "true") == "true") {
                HeroesApp.setMount(color, colorId);
            }

        },

        setHorse : function(id, init) {
            //init为函数参数,表示是否是初始化时候调用
            var color = HeroesApp.getConfig("web_color");
            // 需要在 horse click之前保存color
            id = id || 1;
            this.$("#selectHorse li[data-hid=" + id + "]").trigger("click", init);

            this.setColor(color);
        },

        setColor : function(color) {
            var defaultColor = this.$("#horse_preview .color:eq(0)").attr("data-color");
            color = color || defaultColor;
            var $target = this.$("#horse_preview .color[data-color=" + color + "]")
            //console.log(color)
            $target.trigger("click");
        }
    });

    window.talentView = Backbone.View.extend({
        tagName : "div",

        template : _.template($('#talent_template').html()),

        events : {
            "click #heroTabs .tab" : "clickTab",
            "click #mapList .mapWrapper" : "clickMap",
            "click #mapList .mapWrapper select" : function(e) {
                e.stopPropagation()
            }, // 点击select 停止冒泡
            "mouseover #mapList .mapWrapper select" : function(e) {
                //e.stopPropagation()
            },
            "mouseover #mapList .mapWrapper" : function(e) {
                $(e.currentTarget).find(".mapMask").addClass("in");
            },
            "mouseout #mapList .mapWrapper" : function(e) {
                $(e.currentTarget).find(".mapMask").removeClass("in");
            },
            "change #mapList .mapWrapper select" : "selectChange",
            "click #heroListWrapper .up" : "scrollTop",
            "click #heroListWrapper .down" : "scrollBottom"
        },

        initialize : function() {
            if(appGlobal.enable.talent == "false") {
                this.$el.html("<img id='comming_soon' src=img/comming_soon.png />");
                $("#main").html(this.el);
                $("#page").css({
                    "background" : "url(img/index_background.jpg) no-repeat"
                });
                return false;
            }

            this.listenTo(window.myHeroList, 'add', this.addOne);
            this.listenTo(window.myHeroList, 'reset', this.addAll);

            this.render();

            var handle = this;
            window.myHeroList.fetch({//myHeroList初始化完毕之后
                success : function() {
                    //添加周免Class
                    for(var i in appGlobal.weekfree) {
                        handle.$("#heroList .hero[data-heroid=" + appGlobal.weekfree[i] + "]").addClass("weekfree")
                    }
                    //默认选中第一个英雄
                    handle.$("#heroList .hero:eq(0)").trigger("click");

                    setTimeout(function() {
                        if(!HeroesApp.getConfig("web_IsNotFirstTime_talent", false)) {
                            appGlobal._show_first_talent_tips_modal();
                        }
                    }, 200);

                }
            });

            $("#heroListWrapper").scroll(function(e) {
                var element = $(e.currentTarget);
                
                $("#heroListWrapper .up").removeClass("disabled");
                $("#heroListWrapper .down").removeClass("disabled");
                
                console.log(element.scrollTop())
                console.log($("#heroList").height() - $("#heroListWrapper").height())
                
                if(element.scrollTop() == 0){
                    $("#heroListWrapper .up").addClass("disabled");
                }
                if(element.scrollTop() == $("#heroList").height() - $("#heroListWrapper").height()){
                    $("#heroListWrapper .down").addClass("disabled");
                }
                
            })
        },

        scrollBottom : function(e) {
            this.$("#heroListWrapper").animate({
                scrollTop : $("#heroList").height()
            }, 500);
        },

        scrollTop : function(e) {
            this.$("#heroListWrapper").animate({
                scrollTop : 0
            }, 500);
        },

        clickTab : function(e) {
            var type = $(e.currentTarget).attr("data-type");

            //tab高亮
            this.$("#heroListWrapper .tab").removeClass("active");
            $(e.currentTarget).addClass("active");

            if(type == "all") {//显示全部英雄
                this.$("#heroList .hero").show();
            } else {//显示class带有type的英雄
                this.hideAllHero();
                this.$("#heroList .hero." + type).show();
            }
            
            $("#heroListWrapper").trigger("scroll");
        },

        hideAllHero : function() {
            this.$("#heroList .hero").hide();
        },

        clickMap : function(e) {
            //初始化加点方案
            //this.init_modal_talent_detail(e);
            var mid = $(e.currentTarget).attr("data-mid");
            $("#modal_talent_detail .mapList li[data-mid=" + mid + "]").trigger("click");

            this.show_modal_talent_detail();
        },

        show_modal_talent_detail : function() {
            $("#mask").removeClass("none");
            $("#modal_talent_detail").removeClass("out").addClass("in");
        },

        selectChange : function(e) {
            //改变hero天赋的推荐方案
            var heroId = this.$("#heroList .hero.active").attr("data-heroid");
            var $mapList = this.$("#mapList");
            var TRID = $(e.currentTarget).val();
            var web_hero = [];
            $.each($mapList.find("select"), function(index, select) {
                web_hero.push($(select).val() * 1);
            })

            HeroesApp.setConfig("web_hero" + heroId, web_hero.toString());
            //因为是被动的给数据，所以改变当前集合的数据

            appGlobal._setTalents(heroId, TRID);

            //console.log(window.myHeroList.get(heroId).toJSON())

            //select不要有focus状态
            $(e.currentTarget).blur();
        },

        addOne : function(hero) {
            var view = new heroView({
                model : hero
            });
            this.$("#heroList").append(view.render().el);
        },

        addAll : function() {
            window.myHeroList.each(this.addOne, this);
        },

        render : function() {
            this.$el.html(this.template);
            $("#main").html(this.el);
            $("#page").fadeIn("slow");

        }
    });

    //所有的modal事件都封装在pageView里面
    window.pageView = Backbone.View.extend({
        el : $("#page"),
        events : {
            "click #startButton " : "startGame",
            "click #modal_option .modal_body div" : "toggleEnable",
            "click .modal .close" : "closeModal",
            "click" : "closeFirstTipsModal",
            "click #modal_talent_detail .mapList li" : "init_modal_talent_detail", //点击模态对话框的 地图导航
            "click #modal_talent_detail .planList li" : "init_modal_talent_table", //点击具体方案
            "click #modal_talent_detail .modal_foot .selectPlan " : "clickSelectPlan",
            "mouseover #modal_talent_detail .modal_body .talentImg" : "mouseoverTalentImg",
            "mouseout #modal_talent_detail .modal_body .talentImg" : "mouseoutTalentImg",
            "click #update1_modal .update_button" : "startDownload",
            "click #update3_modal .restart_button" : "restart",
            "click #update_error_modal .redownload_button" : "redownload",
            "click #update_gameRunning_modal .retry_button" : "retryUpdate",
            "click #update_gameRunning_modal .close" : "cancelUpdate",
            "click #update_error_modal .close" : "cancelUpdate"
        },

        template : _.template($('#page_template').html()),

        initialize : function() {
            this.render();
            //设置#modal_option
            this.initOption();
            this.userInfo();
        },

        render : function() {
            this.$el.html(this.template());
            return this;
        },

        retryUpdate : function() {
            if(appGlobal.isGameRunning) {
                return;
            } else {
                $("#update_gameRunning_modal").removeClass("in").addClass("out");
                if(appGlobal.isDownloadCompleted) {//如果后台已经完成下载
                    appGlobal.onUpdateDownloading(100);
                }
            }
        },

        cancelUpdate : function() {
            //取消更新，把所有的modal全部关闭，再启动  #update1_modal
            $(".modal.in").addClass("out").removeClass("in");
            $("#update1_modal").addClass("in").removeClass("out");
        },

        redownload : function() {
            appGlobal.onUpdateDownloading(0);
            $("#update_error_modal").addClass("out").removeClass("in");
            HeroesApp.startDownload();
        },

        restart : function() {
            HeroesApp.update();
        },

        startDownload : function(e) {
            $("#update1_modal").removeClass("in").addClass("out");
            $("#update2_modal").removeClass("out").addClass("in");

            //轮播iframe 写src
            $("#update2_modal .carousel").attr("src", carouselUrl);

            setTimeout(function() {
                HeroesApp.startDownload();

                if(appGlobal.isGameRunning) {
                    $("#update_gameRunning_modal").removeClass("out").addClass("in");
                }

            }, 600)//600ms延迟，modal才显示完毕

        },

        mouseoverTalentImg : function(e) {
            var tid = $(e.currentTarget).attr("data-tid");

            var top = $(e.currentTarget).offset().top + $(e.currentTarget).height() + 10;
            var left = $(e.currentTarget).offset().left;
            $("#tips_talent").find(".name").text(window.appGlobal.talent[tid*1-1]["Name"]);
            $("#tips_talent").find(".descr").text(window.appGlobal.talent[tid*1-1]["Descr"]);

            $("#tips_talent").css({
                left : left,
                top : top
            }).addClass("in");
        },

        mouseoutTalentImg : function() {
            $("#tips_talent").removeClass("in");
        },

        initOption : function() {
            //设置#modal_option
            var enableHorse = HeroesApp.getConfig("web_enableHorse", "true");
            var enableTalent = HeroesApp.getConfig("web_enableTalent", "true");

            if(enableHorse == "true") {
                $("#modal_option #enableHorse").addClass("active")
            } else {
                $("#modal_option #enableHorse").removeClass("active")
            }

            if(enableTalent == "true") {
                $("#modal_option #enableTalent").addClass("active")
            } else {
                $("#modal_option #enableTalent").removeClass("active")
            }
        },

        userInfo : function() {
            //设置用户名与头像
            var userName = HeroesApp.getConfig("web_userName", " ");
            var iconIndex = HeroesApp.getConfig("web_userFace", "1");

            $("#userName").text(userName);
            $("#userFace").attr("src", "img/face/" + iconIndex + ".jpg");
        },

        startGame : function(e) {
            if(!$(e.currentTarget).hasClass("disabled") && !$(e.currentTarget).hasClass("starting")) {

                HeroesApp.startGame();
            }

            $(e.currentTarget).addClass("starting");

        },

        toggleEnable : function(e) {
            $(e.currentTarget).toggleClass("active");
            HeroesApp.setConfig("web_" + $(e.currentTarget).attr("id"), $(e.currentTarget).hasClass("active").toString());
            appGlobal.userEnable.enableHorse = $("#enableHorse").hasClass("active").toString();
            appGlobal.userEnable.enableTalents = $("#enableTalent").hasClass("active").toString();
        },

        closeModal : function(e) {

            $(e.currentTarget).parents(".modal").removeClass("in").addClass("out");
            if($(".modal.in").length == 0) {//没有其他对话框的时候
                $("#mask").addClass("none");
            }

            //appGlobal._show_first_shop_tips_modal 中设置了class
            $("#selectHorse ul li").removeClass("first_tips");
            $("#mapList .mapWrapper:eq(0)").removeClass("first_tips");
            e.stopPropagation()

            if($(e.currentTarget).parents(".modal").attr("id") == "modal_option") {//设置不想吐则
                if(appGlobal.currentPage == "shop") {//shop页面
                    if(appGlobal.userEnable.enableHorse == "false") {
                        appGlobal._renderFunctionDisabledPage();
                    } else {
                        appGlobal._hideFunctionDisabledPage();
                    }

                }

                if(appGlobal.currentPage == "talent") {//talent页面
                    if(appGlobal.userEnable.enableTalents == "false") {
                        appGlobal._renderFunctionDisabledPage();
                    } else {
                        appGlobal._hideFunctionDisabledPage();
                    }
                }

            }

        },

        closeFirstTipsModal : function(e) {

            $(".first_tips_modal.in .modal_head .close").trigger("click")

        },

        init_modal_talent_detail : function(e) {
            var mid = $(e.currentTarget).attr("data-mid");
            var hid = this.$("#heroList .hero.active").attr("data-heroid");
            var $planList = this.$("#modal_talent_detail .modal_body .planList");
            var $mapList = this.$("#modal_talent_detail .modal_body .mapList");

            //改变modal_head
            var $modal_head = this.$("#modal_talent_detail .modal_head");
            $modal_head.find(".name").text(window.myHeroList.get(hid).get("Name"));
            $modal_head.find(".face").attr("src", "data/Hero/h" + hid + ".png");
            //改变样式
            $mapList.find("li").removeClass("active");
            $(e.currentTarget).addClass("active");

            //先清除所有recommend，再添加
            $planList.find("li").remove();

            var recommend = [];
            recommend = $.grep(window.myHeroList.get(hid).get("recommend"), function(val, key) {
                if(val["Map"] == mid) {
                    return true;
                }
            }, false);

            var liTemplate = _.template($("#planList_li_template").html());

            for(var i in recommend) {
                //console.log(JSON.stringify(recommend[i]))
                var $temp = liTemplate(recommend[i]);
                $planList.append($temp);
            }

            //设置active
            var active_TRID = $("#mapList").find("[data-mid=" + mid + "] select").val();

            $planList.find("[data-trid=" + active_TRID + "]").addClass("active").addClass("selected").trigger("click");

            //console.log("mid:" + mid + ",heroid:" + hid);
        },
        init_modal_talent_table : function(e) {
            //因为没有用户自定义的天赋方案，所以从全局window.appGlobal.recommend取值更方便
            var TRID = $(e.currentTarget).attr("data-TRID");
            var heroid = this.$("#heroList .hero.active").attr("data-heroid");
            var $table = this.$("#modal_talent_detail .modal_body .talentList");

            $(e.currentTarget).addClass("active").siblings().removeClass("active");

            //如果active且selected，选择按钮disabled
            if($(e.currentTarget).hasClass("selected")) {
                this.$("#modal_talent_detail .modal_foot .selectPlan").addClass("disabled");
            } else {
                this.$("#modal_talent_detail .modal_foot .selectPlan").removeClass("disabled");
            }

            //console.log("TRID:" + TRID + ",heroid:" + heroid);

            //先清空，再添加
            $table.find("img").remove();

            //TRID-1 即是index
            var recommend = window.appGlobal.recommend[TRID - 1];
            for(var m = 0; m < 7; m++) {//7次加点
                var n = m * 3 + 1;
                n = n == 19 ? 20 : n;

                var heroModel = window.myHeroList.get(heroid);

                var talentArray = heroModel.get("TIDLV" + n).split(",");

                //console.log(talentArray)

                for(var i in talentArray) {
                    var $img = $("<img src=data/Talent/t" + talentArray[i] + ".png >").addClass("talentImg").attr("data-tid", talentArray[i]);
                    if(talentArray[i] == recommend["LV" + n + "TID"]) {//添加推荐高亮
                        $img.addClass("active");
                    }
                    $table.find("tbody tr:eq(" + m + ") td:eq(" + (i * 1 + 1) + ")").append($img);
                }

            }

        },
        clickSelectPlan : function(e) {
            var heroId = this.$("#heroList .hero.active").attr("data-heroid");
            var $planList = this.$("#modal_talent_detail .modal_body .planList");
            var $mapList = this.$("#mapList");
            var $modal_mapList = this.$("#modal_talent_detail .modal_body .mapList");
            var mid = $modal_mapList.find(".active").attr("data-mid");

            //设置选中样式与修改select值
            if($planList.find("li.selected").hasClass("active")) {
                return false;
            } else {
                $planList.find("li.selected").removeClass("selected");
                $planList.find("li.active").addClass("selected");

                //console.log($mapList.find(".mapWrapper[data-mid=" + mid + "] select"))

                $mapList.find(".mapWrapper[data-mid=" + mid + "] select").val($planList.find("li.selected").attr("data-trid")).trigger("change");

                //设置disabled
                $(e.currentTarget).addClass("disabled");
            }
        }
    });

    window.specialView = Backbone.View.extend({
        el : $("#page"),
        template : _.template($('#special_template').html()),

        events : {
            "click .addGameButton" : "clickAddGameButton"
        },

        initialize : function() {
            this.render();
        },

        render : function() {
            this.$el.html(this.template());
            return this;
        },

        clickAddGameButton : function() {
            HeroesApp.browseDirectory();
        }
    });

    window.myRouter = Backbone.Router.extend({
        routes : {
            "" : "showShop",
            "shop" : "showShop", // #shop
            "talent" : "showTalent" // #talent
        },

        showShop : function() {
            console.log("showShop");
            appGlobal.currentPage = "shop";
            $("#page").css({
                "background" : "url(img/index_background.jpg) no-repeat"
            });
            if(window.myAppShopView) {
                window.myAppShopView.remove();
            }

            window.myHorseList = new horseList;
            window.myAppShopView = new shopView;

            $("#tab_talent").removeClass("active");
            $("#tab_shop").addClass("active");

            if(appGlobal.userEnable.enableHorse == "false") {
                appGlobal._renderFunctionDisabledPage();
            } else {
                appGlobal._hideFunctionDisabledPage();
            }

        },

        showTalent : function() {
            console.log("showTalent");
            appGlobal.currentPage = "talent";
            $("#page").css({
                "background" : "url(img/talent_background.jpg) no-repeat"
            });
            if(window.myAppTalentView) {
                window.myAppTalentView.remove();
            }
            window.myHeroList = new heroList;
            window.myAppTalentView = new talentView;

            $("#tab_shop").removeClass("active");
            $("#tab_talent").addClass("active");

            if(appGlobal.userEnable.enableTalents == "false") {
                appGlobal._renderFunctionDisabledPage();
            } else {
                appGlobal._hideFunctionDisabledPage();
            }

        }
    });

    window.router = new myRouter();

    //统计信息
    //appGlobal._count();
    //appGlobal._checkInstall()
    if(appGlobal._checkInstall()) {
        appGlobal._init();
    } else {
        window.myPageView = new specialView;
    }

    //setTimeout(function(){Backbone.history.start();},2000)
    //appGlobal.onSetUserInfo("wty",2)

})

